package org.september.pisces.operation;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.september.pisces.module.api.PiscesModule;
import org.september.pisces.module.api.WebMenu;
import org.september.pisces.operation.controller.DbBackupController;
import org.september.pisces.operation.service.DbBackupService;
import org.september.pisces.task.service.DynamicScheduledTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;


/**
 * 工程名应该改成 pisces-operation
 * 标注service，用于主工程发现插件模块
 *
 * @author yexinzhou
 */
@Configuration
@ComponentScan(basePackageClasses = OperationModule.class)
public class OperationModule implements PiscesModule {

    @Autowired
    DynamicScheduledTaskService dynamicScheduledTaskService;

    @Autowired
    DbBackupService dbBackupService;

    public static final String 数据库备份 = "数据库备份";
    private static Map<String, List<WebMenu>> moduleMap = new HashMap<>();

    static {
        List<WebMenu> menus1 = new ArrayList<>();
        menus1.add(new WebMenu("运行维护-数据库备份", DbBackupController.List_Page, "layui-icon-circle")
                .addPermission("数据库备份", OperationPermission.数据库备份.getUrls()));
        moduleMap.put(数据库备份, menus1);
    }

    //	public static final String Operation_List = "运行维护-日志列表";
//	public static final String Settings_Status = "运行维护-系统状态";
    public OperationModule() {
        System.out.println(this.getClass().getName() + " init..");
    }

    public String[] getMyBatisMapperLocation() {
        return new String[]{"classpath:" + OperationModule.class.getPackageName().replace(".", "/") + "/mapper/*.xml"};
    }

    public String[] getEntityPackages() {
        return new String[]{OperationModule.class.getPackageName() + ".entity"};
    }

    public static List<WebMenu> getWebMenus(String moduleName) {
        return moduleMap.get(moduleName);
    }

    public void init() {
        dynamicScheduledTaskService.每天X点Y分运行("数据库备份", 3, 0, dbBackupService, "dbBackup");
    }

}
